package cn.hh.wechatkit.pojo.message;

import cn.hh.wechatkit.exception.Wx_Exception_InvalidParam;

import java.util.HashMap;
import java.util.Map;

/**
 * Created this one by HMH on 2017/7/11.
 */
public enum Wx_MsgTypeEnum {

    text,
    event,
    voice,
    video,
    image,
    music,
    link,
    news,
    article
    ;

    private static final Map<String, Wx_MsgTypeEnum> stringToEnum = new HashMap<>();
    static{
        for(Wx_MsgTypeEnum e : values()){
            stringToEnum.put(e.name(), e);
        }
    }

    public static Wx_MsgTypeEnum fromString(String name,String fieldName){
        Wx_MsgTypeEnum result = stringToEnum.get(name);
        if (result == null) {
            throw new Wx_Exception_InvalidParam(fieldName+"枚举字段错误");
        }
        return result;
    }

}
